#define layout()
#@_jsscss()
<title>#(session.WXACCOUNT.name)</title>
<style type="text/css">
	.w3000{
		margin-right: 50px;
	}
</style>
</head>
<body>
<div class="centerMain">
        <div class="ui-form" style="margin-top:1px;display: flex;">
        		<div class="ui-form-item ui-border-b" style="float:left;padding: 15px 10px;">
            	<img src="/wx/images//addressee-icon.png" alt="alt" style="width:48px;" title="title" />
            </div>
            <div class="ui-form-item ui-border-b" style="line-height:24px;padding: 15px 10px;width: 100%; " id="receiveinfo">
                <ul style="font-family: 微软雅黑;font-size: 16px;"><lable id="receivename">#(session.ADDMAP.receivename ?? "")</lable><lable style="padding-left: 20px;" id="receivephone">#(session.ADDMAP.receivephone ?? "")</lable></ul>
                #if(session.BNORDER)
                <ul style="color:#999999;font-size: 16px;"><lable id="receivecard">#(session.ADDMAP.receivecard ?? "")</lable></ul>
                #end
                <ul style="color:#999999;font-size: 16px;"><lable id="receiveadd">#(session.ADDMAP.receiveadd ?? "")</lable></ul>
            </div>
            <div class="ui-form-item ui-border-b" style="padding: 15px 10px;float:right;">
               	<img src="/wx/images/icon-addr.png" alt="alt" style="width:48px;" title="title"  id="useradd" />
            </div>
       </div>
       <div class="mt10 ui-form" id="shop_div">
		    		<div class="ui-form-item" style="line-height:44px;padding-left: 20px;float:left;">
		            门店
		        </div>
		        <div class="ui-form-item" style="line-height:44px;padding-left: 20px;text-align:right;float:right;width:70%;">
		           <input class="w300" style="text-align:right;padding-right:10px;padding-left:0px;" id="shopname" name="shopname" value="#(session.ADDMAP.shopname ?? "")" placeholder="请选择门店">
		           <input class="w300" style="text-align:right;padding-right:10px;padding-left:0px;" type="hidden" id="shopid" name="shopid" value="#(session.ADDMAP.shopid ?? "")" >
		        </div>
		        <div style="clear:both;height:0px;"></div>
		</div>
       <div class="mt10 ui-form">
		    		<div class="ui-form-item" style="line-height:44px;padding-left: 20px;float:left;">
		            订单号
		        </div>
		        <div class="ui-form-item" style="float:right;padding-top:10px;padding-right:20px;" id="scanQRCode">
					<img src="/wx/images/sm-ico.png" alt="alt" style="width:24px;z-index:999;" title="title" id="scanQRCode" />
				</div>
		        <div class="ui-form-item" style="line-height:44px;padding-left: 20px;text-align:right;float:right;width:60%;">
		            <input class="w300" style="text-align:right;padding-right:10px;padding-left:0px;"  id="orderNo" name="orderNo" value="" >
		        </div>
		        
		        <div style="clear:both;height:0px;"></div>
		</div>
        <div class="mt10 ui-form">
		    		<div class="ui-form-item" style="line-height:44px;padding-left: 20px;float:left;">
		            重量(KG)
		        </div>
		        <div class="ui-form-item" style="line-height:44px;padding-left: 20px;text-align:right;float:right;width:60%;">
		            <input class="w300" style="text-align:right;padding-right:10px;padding-left:0px;" type="number" id="weight" name="weight" value="" >
		        </div>
		        <div style="clear:both;height:0px;"></div>
		</div>
		 <div class="mt10 ui-form">
		    		<div class="ui-form-item" style="line-height:44px;padding-left: 20px;float:left;">
		            备注
		        </div>
		        <div class="ui-form-item" style="line-height:44px;text-align:left;float:left;width:86%;">
		            <textarea style="width: 100%;height: 80px;" placeholder="备注信息" id="remark" name="remark" maxlength="50" ></textarea>
		        </div>
		        <div style="clear:both;height:0px;"></div>
		</div>
        <div class="ui-btn-wrap mt20 ui-form" style="clear:both">
            <input id="Submit1" type="button" class="ui-btn-lg ui-btn-success"  value="确认寄件" />
        </div>
</div>
<div class="clear"></div>
</body>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
    <script type="text/javascript">
	var flag = true;
	wx.config({
				debug: false,
				appId: '#(appId)',
				timestamp: '#(timestamp)',
				nonceStr: '#(nonceStr)',
				signature: '#(signature)',
				jsApiList: [
					'scanQRCode',
					'openLocation',//使用微信内置地图查看地理位置接口  
                  'getLocation' //获取地理位置接口  
				]
   });
    wx.ready(function(){    		
		    
		  // 7.2 获取当前地理位置  
		  document.querySelector('#shop_div').onclick = function () {  
		    wx.getLocation({  
		      success: function (res) {  
		        var lat = res.latitude;
	            var lng = res.longitude;
	            var url = "/jlforder/getShopByCoordinate?appid=#(session.appid)&LNG="+lng+"&LAT="+lat;
	            window.location.href=url;
		      },  
		      cancel: function (res) {  
		        alert('用户拒绝授权获取地理位置');  
		      }  
		    });  
		  };  
		  // 7 地理位置接口 结束   
		      
		});    
		$("#scanQRCode").bind("click", function() {
				wx.scanQRCode({
					// 默认为0，扫描结果由微信处理，1则直接返回扫描结果
					needResult: 1,
					desc: 'scanQRCode desc',
					success: function(res) {
						//扫码后获取结果参数赋值给Input
						var url = res.resultStr;
                    //商品条形码，取","后面的
                        if(url.indexOf(",")>=0){
	                        	var tempArray = url.split(',');
	                        var tempNum = tempArray[1];
						    $("#orderNo").val(tempNum);
						}
					}
				});
			});
		 //初始化jsapi接口 状态  
		wx.error(function (res) {  
		  alert("调用微信jsapi返回的状态:"+res.errMsg);  
		});  
	function check(flag,errmsg){
		flag = true;
	    	var receivename = $("lable#receivename").text();
	    	var receivephone = $("lable#receivephone").text(); 
	    	var receiveadd = $("lable#receiveadd").text();
	    	var weight = parseFloat($("#weight").val());
	    	var orderNo = $("#orderNo").val();
		//电话号码
		var reg=/^(\d{3}-)(\d{8})$|^(\d{3})(\d{8})$|^(\d{4}-)(\d{7})$|^(\d{4}-)(\d{8})$|^(\d{4})(\d{8})$/;
		var objExp=new RegExp(reg);
		var 	shopid = $("#shopid").val();
		
		if(!objExp.test(receivephone)){
			return "收件人人电话号码格式错误";
		}
		if(receivename == ''){
			return "收件人姓名不能为空";
		}
		if(orderNo == ''){
			return "订单号不能为空";
		}
		if(receiveadd == ''){
			return "收件人地址不能为空";
		}
		if(shopid == ''){
			return "请先选择门店";
		}
		if(isNaN(weight)){
			return "重量必须为数字";
		}
		return "ok";
	}
	var orderinfo = new Object;
	function bindval(){
		orderinfo = new Object;
		orderinfo.sendname = $("lable#sendname").text();
	    	orderinfo.sendphone = $("lable#sendphone").text(); 
	    	orderinfo.sendadd = $("lable#sendadd").text(); 
	    	orderinfo.receivename = $("lable#receivename").text();
	    	orderinfo.receivephone = $("lable#receivephone").text(); 
	    	orderinfo.receiveadd = $("lable#receiveadd").text();
	    	orderinfo.expressTime = $("#timetype").val();
	    	orderinfo.shopid = $("#shopid").val();
	    	orderinfo.shopname = $("#shopname").val();
	    	orderinfo.sendcard = $("#sendcard").val();
	    	orderinfo.receivecard= $("#receivecard").val();
	    	orderinfo.remark = $("#remark").val();
	}
	function addbind()
	{
		
		$("#bbbb").bind("click",function(){
			bindval();
	        window.location.href="/jlforder/toEditUserAdd?appid=#(session.appid)&state=9&sendcard="+orderinfo.sendcard+"&receivecard="+orderinfo.receivecard+"&expreee_time="+orderinfo.expressTime+"&sendname="+orderinfo.sendname+"&sendphone="+orderinfo.sendphone+"&sendadd="+orderinfo.sendadd+"&receivename="+orderinfo.receivename+"&receivephone="+orderinfo.receivephone+"&receiveadd="+orderinfo.receiveadd;
	    });
		$("#useradd").bind("click",function(){
		bindval();
        window.location.href="/jlforder/toUserAdd?appid=#(session.appid)&orderinfo="+JSON.stringify(orderinfo);
	   });
	    $("#receiveinfo").bind("click",function(){
	    	 bindval();
	    	  window.location.href="/jlforder/toEditUserAdd?appid=#(session.appid)&state=1&orderinfo="+JSON.stringify(orderinfo);
//	     window.location.href="/jlforder/toEditUserAdd?appid=#(session.appid)&sendcard="+orderinfo.sendcard+"&receivecard="+orderinfo.receivecard+"&state=1&receivename="+orderinfo.receivename+"&receivephone="+orderinfo.receivephone+"&receiveadd="+orderinfo.receiveadd+"&sendname="+orderinfo.sendname+"&sendphone="+orderinfo.sendphone+"&sendadd="+orderinfo.sendadd;
	    });
	}
	function removebind()
	{
		$("#useradd").unbind("click");
		$("#receiveinfo").unbind("click");
		$("#sendinfo").unbind("click");
	}
	addbind();
	
	$("#Submit1").bind("click",function(){
		if(confirm("确认下单")){
			var flag = true;
			var mess="";
			mess = check(flag,mess);
			if(mess!="ok"){
				alert(mess);
				return;
			}
		    	var receiveAddArr = $("lable#receiveadd").text().split("^");
			var receiveProCityDis = receiveAddArr[0].split("||");
			var receivePro = receiveProCityDis[0];
			var receiveCity = receiveProCityDis[1];
			var receiveDis = receiveProCityDis[2];
		    	var receivename = $("lable#receivename").text();
		    	var receivephone = $("lable#receivephone").text(); 
		    	var receiveadd =receiveAddArr[1];
		    	var weight = parseFloat($("#weight").val());
		    	var shopid = $("#shopid").val();
	        var shopname = $("#shopname").val();
	      	var receivecard= $("#receivecard").text();
	      	var remark = $("#remark").val();
	      	var order_no = $("#orderNo").val();
		    	if(isNaN(weight)){
				weight = 0;
			}
		    	var myObject = { 
		    		"wxOrder.order_no" : order_no,
				"wxOrder.receive_card" : receivecard,
				"wxOrder.receive_pro" : receivePro,
				"wxOrder.receive_city" : receiveCity,
				"wxOrder.receive_dis" : receiveDis,
				"wxOrder.receive_name" : receivename,
				"wxOrder.receive_phone" : receivephone, 
				"wxOrder.receive_add" : receiveadd,
				"wxOrder.remark" : remark,
				"wxOrder.weight" : weight
			}
		    	flag = false;
	    		$("#Submit1").val("提交中");
	    		// 禁用按钮防止重复提交
		    $("#Submit1").attr({ disabled: "disabled" });
	    		addbind();
		    	$.ajax( {
	            url: "/jlforder/addOrder?appid=#(session.appid)&shopid="+ $("#shopid").val(),
	            data: myObject,
	            type: 'POST',
	            async: false,
	            dataType: "json",
	            beforeSend: function () {
			        
			    },
	            success: function (result)
	            {
	               	$("#Submit1").removeAttr("disabled");
	              	$("#Submit1").val("确认寄件");
	            	    if(result.state=="ok"){
	            	    	    $("#weight").val("");
						alert("下单成功，我们将尽快安排递送员上门取件，请您耐心等待!订单号+"+result.ORDERNO);
	            	    }else{
	            		    alert(result.ERRMESSAGE);
	                }
	            }, 
	            failed: function ()
	            {
	               
	            },complete:function()
	            {
	              	
	            }
	        })
		}
		else{
			return false;
		}
    });
    
    $("#Submit2").bind("click",function(){
    		$("lable#receivename").text('');
	    $("lable#receivephone").text(''); 
	    $("lable#receiveadd").text('');
	    $("#receivecard").text('');
	    $("#weight").val('');
    });
</script>


</html>
#end
#@layout()